package com.haixiaoke.business;

import com.haixiaoke.common.annotation.Log;
import com.haixiaoke.common.core.domain.AjaxResult;
import com.haixiaoke.common.core.page.TableDataInfo;
import com.haixiaoke.common.enums.BusinessType;
import com.haixiaoke.common.utils.poi.ExcelUtil;
import com.haixiaoke.domain.LockCommandLog;
import com.haixiaoke.service.ILockCommandLogService;
import com.haixiaoke.system.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 智能锁指令下发记录Controller
 *
 * @author qixi
 * @date 2023-05-29
 */
@RestController
@RequestMapping("/business/commandLog")
public class LockCommandLogController extends BaseController {
    @Autowired
    private ILockCommandLogService lockCommandLogService;

    /**
     * 查询智能锁指令下发记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:command_log:list')")
    @GetMapping("/list")
    public TableDataInfo list(LockCommandLog lockCommandLog) {
        startPage();
        List<LockCommandLog> list = lockCommandLogService.selectLockCommandLogList(lockCommandLog);
        return getDataTable(list);
    }

    /**
     * 导出智能锁指令下发记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:command_log:export')")
    @Log(title = "智能锁指令下发记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LockCommandLog lockCommandLog) {
        List<LockCommandLog> list = lockCommandLogService.selectLockCommandLogList(lockCommandLog);
        ExcelUtil<LockCommandLog> util = new ExcelUtil<LockCommandLog>(LockCommandLog.class);
        util.exportExcel(response, list, "智能锁指令下发记录数据");
    }

    /**
     * 获取智能锁指令下发记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:command_log:query')")
    @GetMapping(value = "/{commandId}")
    public AjaxResult getInfo(@PathVariable("commandId") Long commandId) {
        return success(lockCommandLogService.selectLockCommandLogByCommandId(commandId));
    }

    /**
     * 新增智能锁指令下发记录
     */
    @PreAuthorize("@ss.hasPermi('business:command_log:add')")
    @Log(title = "智能锁指令下发记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LockCommandLog lockCommandLog) {
        return toAjax(lockCommandLogService.insertLockCommandLog(lockCommandLog));
    }

    /**
     * 修改智能锁指令下发记录
     */
    @PreAuthorize("@ss.hasPermi('business:command_log:edit')")
    @Log(title = "智能锁指令下发记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LockCommandLog lockCommandLog) {
        return toAjax(lockCommandLogService.updateLockCommandLog(lockCommandLog));
    }

    /**
     * 删除智能锁指令下发记录
     */
    @PreAuthorize("@ss.hasPermi('business:command_log:remove')")
    @Log(title = "智能锁指令下发记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{commandIds}")
    public AjaxResult remove(@PathVariable Long[] commandIds) {
        return toAjax(lockCommandLogService.deleteLockCommandLogByCommandIds(commandIds));
    }
}
